package com.group.utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import net.bytebuddy.asm.Advice.This;

/**
 * 
 * Hibernate初始化
 * 
 * @author spj
 * @version 1.0
 */
public class HibernateUtil {
	
	private static SessionFactory sessionFactory;
	
	/**
	 * 获取SessionFactory对象
	 * 
	 * @return	SessionFactory对象
	 */
	public static SessionFactory getSessionFactory() {
		if (sessionFactory == null) {
			Configuration cfg = new Configuration();
			cfg.configure("hibernate.cfg.xml");
			sessionFactory = cfg.buildSessionFactory();
		}
		return sessionFactory;
	}
	
	/**
	 * 获取Session对象
	 * 
	 * @return	session
	 */
	public static Session openSession() {
		return getSessionFactory().openSession();
	}

}
